package cn.sjx.graduate.web.controller;

import cn.sjx.graduate.domain.Employee;
import cn.sjx.graduate.qo.StaffTypeQuery;
import cn.sjx.graduate.service.IRedisService;
import cn.sjx.graduate.service.IStaffService;
import cn.sjx.graduate.util.JsonResult;
import cn.sjx.graduate.util.TokenUtil;
import cn.sjx.graduate.vo.StaffVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: bo-feifei
 * @Date 2022/1/17 17:14
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private IStaffService staffService;
    @Autowired
    private IRedisService redisService;

    @PostMapping("/query")
    @ApiOperation("首页展示工资数据")
    public JsonResult<IPage<StaffVO>> query(@RequestBody StaffTypeQuery qo, HttpServletRequest request) {
        String token = TokenUtil.getToken(request);
        Employee employee = redisService.getUserByToken(token);
        if (employee == null) {
            return JsonResult.error("当前未登录用户");
        }
        IPage<StaffVO> query = staffService.queryPage(qo, employee);

        return JsonResult.success(query);
    }
}
